#ifndef __SN32F280_KB_API_H
#define __SN32F280_KB_API_H

/*_____ I N C L U D E S ____________________________________________________*/
#include <SN32F280.h>

/*_____ D E F I N I T I O N S ______________________________________________*/
#define	API_ONLINE_CNT		50					//5sec@100ms

/* APP State Machine*/
#define		S_APP_CHECK_STATE  		0x00
#define		S_APP_READ_STATE  		0x01
#define		S_APP_WRITE_STATE  		0x02
#define		S_APP_END_STATE 	 		0x03
#define		S_APP_CONNECT_STATE		0x04
#define		S_APP_FALSH_STATE			0x05
#define		S_APP_TEMP_STATE			0x06

#define		 BOOT_MODE		0x00

/* APP bAPP_Status Register */
#define mskAPP_Processed			(0x1<<0)
#define mskAPP_LEDUpdate			(0x1<<1)
#define mskAPP_ProfileUpdate	(0x1<<2)
#define mskAPP_CmdAck					(0x1<<3)

#define mskAPP_CmdCorrect			(0x1<<4)
#define mskAPP_CmdEnd					(0x1<<5)
#define	mskAPP_DefaultKey			(0x1<<6)
/* APP Command list */
#define	APP_CMD_END			0x02

#define	APP_CMD_INFO_R	0x05

#define	APP_CMD_KEY_R		0x10
#define	APP_CMD_KEY_W		0x11

#define	APP_CMD_LED_R		0x12
#define	APP_CMD_LED_W		0x13

#define	APP_CMD_MAR_R		0x14
#define	APP_CMD_MAR_W		0x15

#define	APP_CMD_GAM_R		0x16
#define	APP_CMD_GAM_W		0x17

#define	APP_CMD_FN_R			0x26
#define	APP_CMD_FN_W			0x27

#define	APP_CMD_TEMP_W	0x28

#define APP_CMD_ENABLE_KEYCUSTOMIZE		0x18
#define APP_CMD_DISABLE_KEYCUSTOMIZE	0x19
#define	APP_CMD_LED_CUSTONIZE					0x20

#define	APP_CMD_LEDCON_R			0x22
#define	APP_CMD_LEDCON_W			0x23

#define	APP_CMD_ALLFLASH_W		0x38
#define	APP_CMD_AIMAFLASH_W		0x72

#define	APP_CMD_LED_UPLOAD		0xF5
#define	APP_CMD_LED_BATLOAD		0xF6


#define APP_CMD_KEEPALIVE			0xE0

#define APP_CMD_CONNECT				0xAB

#define	APP_CMD_LED_EFFECT_START	0xF0
#define	APP_CMD_LED_SYNC_INIT	0xF1
#define	APP_CMD_LED_SYNC	0xF2
#define	APP_CMD_LED_SYNC_END	0xF3


/* APP Area page size list */
#define APP_KEY_DEFINED_PAGES 	9	//Total---640 Bytes----10 Pages-//
#define APP_LED_EFFECT_PAGES 		1		//Total---1280 Bytes----20 Pages-//
#define	APP_LED_CON_PAGES				9
#define APP_MACRO_PAGES					48	//Total---3072 Bytes----48 Pages-//
#define APP_DEVICE_INFO_PAGES		 2	//Total---128 Bytes----2 Pages-//
#define APP_GAME_PROFILE_PAGES	 1	//Total---64 Bytes----1 Page-//


#define APP_CMD_HEADER			0x04
#define APP_CMD_ACK			0x01
#define APP_CMD_NACK		0xFF
#define APP_PROGRAM_LENGTH		0x10
#define mskAPP_CmdStart 0x01

/* APP bAPP_Profile Register*/
#define mskAPP_Gamemode 0x10
#define mskAPP_DisableALT_Tab 0x20
#define mskAPP_DisableALT_F4 0x40
#define mskAPP_DisableWindows 0x80

typedef struct
{
	volatile uint8_t	mode;
	volatile uint8_t	rDuty;
	volatile uint8_t	gDuty;
	volatile uint8_t	bDuty;
	volatile uint8_t	rDuty_OLED;
	volatile uint8_t	gDuty_OLED;
	volatile uint8_t	bDuty_OLED;
	volatile uint8_t	colour;
	volatile uint8_t	light;
	volatile uint8_t	speed;
	volatile uint8_t	dir;	
	volatile uint8_t	colour_OLED;
	volatile uint8_t	light_OLED;
	volatile uint8_t	speed_OLED;
	volatile uint8_t	dir_OLED;	
}API_Set;

extern API_Set		API_User_Set;
/*_____ M A C R O S ________________________________________________________*/

/*_____ D E C L A R A T I O N S ____________________________________________*/
extern uint8_t	bAPP_State;
extern uint8_t	bAPP_Status;	
extern uint8_t bAPP_Profile;
extern uint8_t LED_API_Off;
extern uint8_t bAPP_LED_Customize;
extern uint8_t rAPI_OnLineCnt;
extern uint8_t rBatBuf;
extern uint16_t dbAPP_PageLength;

extern uint8_t rAPI_IdleCnt;
extern uint8_t f_FN_Toggle;
extern uint8_t f_FN_Lock;


extern uint32_t rEx_FlashAddr;
extern uint32_t rAimaFrame_Index;
extern uint32_t rAimaFrame_Len;

extern void APP_CheckTimeout(void);
extern void KB_API(void);
extern void API_Param_Load(void);
extern void APP_Connect(void);

extern const uint32_t API_INFOR_TAB[];
extern const uint32_t API_KEY_TAB[];
extern const uint32_t API_LED_TAB[];
extern const uint32_t API_GM_TAB[];
extern const uint32_t API_FN_KEY_TAB[];
extern const uint32_t API_MACRO_TAB[];

#endif	/* __SN32F280_KB_API_H */
